//
//  ZLTogetherLearnHomeTableViewCell.m
//  ZLExamination
//
//  Created by Lei_Zhong_Xun on 2017/8/15.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLTogetherLearnHomeTableViewCell.h"

#import "ZLTogetherLearnModel.h"

@implementation ZLTogetherLearnHomeTableViewCell

- (void)setModel:(ZLTogetherLearnModel *)model {
    _model = model;
    
    _titleLbl.text = _model.title;
    _quantityLbl.text = [NSString stringWithFormat:@"学习量: %.0f%%",_model.percent*100];
    _percentLbl.text = [NSString stringWithFormat:@"%@课时",_model.chapter_number];
    
    [_baseProView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_percentLbl.mas_right).offset(15);
        make.width.mas_equalTo(180);
        make.height.mas_equalTo(10);
        make.centerY.equalTo(_percentLbl);
    }];
    
    
    [_proView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_baseProView);
        make.width.mas_equalTo(180*_model.percent);
        make.height.mas_equalTo(10);
        make.centerY.equalTo(_baseProView);
    }];


}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.titleLbl];
        [self.contentView addSubview:self.quantityLbl];
        [self.contentView addSubview:self.percentLbl];
        [self.contentView addSubview:self.baseProView];
        [self.contentView addSubview:self.proView];
        
        [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.mas_equalTo(14);
        }];
        
        [_quantityLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_titleLbl.mas_right).offset(20);
            make.centerY.equalTo(_titleLbl);
        }];
        
        [_percentLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_titleLbl);
            make.top.equalTo(_titleLbl.mas_bottom).offset(8);
        }];
        
        
    }
    return self;
}

- (UILabel *)titleLbl {
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = kMyFont(13);
    }
    return _titleLbl;
}

- (UILabel *)quantityLbl {
    if (!_quantityLbl) {
        _quantityLbl = [[UILabel alloc] init];
        _quantityLbl.font = kMyFont(11);
        _quantityLbl.textColor = [UIColor grayColor];
    }
    return _quantityLbl;
}

- (UILabel *)percentLbl {
    if (!_percentLbl) {
        _percentLbl = [[UILabel alloc] init];
        _percentLbl.font = kMyFont(13);
        _percentLbl.textColor = [UIColor darkGrayColor];
    }
    return _percentLbl;
}

- (UIView *)baseProView {
    if (!_baseProView) {
        _baseProView = [[UIView alloc] init];
        _baseProView.layer.backgroundColor = [kRGB_COLOR(242, 242, 242, 1) CGColor];;
        _baseProView.layer.cornerRadius = 5;
    }
    return _baseProView;
}

- (UIView *)proView {
    if (!_proView) {
        _proView = [[UIView alloc] init];
        _proView.layer.backgroundColor = [kMY_BLUE_COLOR CGColor];
        _proView.layer.cornerRadius = 5;
    }
    return _proView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
